package com.elephant.bean.selfEditor;

import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.PropertyEditorRegistrySupport;

import java.beans.PropertyEditor;

/**
 * @author 林
 * @create 2025-05-22 11:06
 */
//注册器
public class AddressPropertyEditorRegistrar implements PropertyEditorRegistrar
{
	@Override
	public void registerCustomEditors(PropertyEditorRegistry registry) {
		doRegisterEditor(registry, Address.class, new AddressEditor());
	}

	private void doRegisterEditor(PropertyEditorRegistry registry, Class<?> requiredType, PropertyEditor editor) {
		if (registry instanceof PropertyEditorRegistrySupport) {
			((PropertyEditorRegistrySupport) registry).overrideDefaultEditor(requiredType, editor);
		}
		else {
			registry.registerCustomEditor(requiredType, editor);
		}
	}
}
